<template>
    <div class="detail">
        <div class="det_head">
            <van-icon name="arrow-left" @click="()=>{this.$router.go(-1)}" />
            <p>{{detailData.community}}</p>
            <i class="icon iconfont icon-a-fenxiang7"></i>
        </div>
        <div class="detmain">
          <div class="banner">
            <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
              <van-swipe-item v-for="(v,i) in detailData.houseImg" :key="i">
                <img :src="'http://47.102.145.189:8009' + v" alt="">
              </van-swipe-item>
            </van-swipe>
            <li>{{detailData.title}}</li>
            <li>
              <van-tag plain type="primary" size="medium">标签</van-tag>
            </li>
          </div>
          <div class="desc">
            <li>
              <p>{{detailData.price}} <span>/月</span></p>
              <p>租金</p>
            </li>
            <li>
              <p>{{detailData.roomType}}</p>
              <p>房型</p>
            </li>
            <li>
              <p>{{detailData.size}}平米</p>
              <p>面积</p>
            </li>
          </div>
          <div class="floor">
            <li><p><span>装修：</span>{{detailData.description}}</p><p><span>朝向：</span>{{oriented}}</p></li>
            <li><p><span>楼层：</span>{{detailData.floor}}</p><p><span>类型：</span>普通住宅</p></li>
          </div>
          <div class="community">
            <li>小区：{{detailData.community}}</li>
            <div class="msp-main" id="container"></div>
          </div>
        </div>
        <div class="detfoot">
          <button>收藏</button>
          <button>在线咨询</button>
          <button>电话预约</button>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      detailData: {},
      coord: {},
      oriented: '',
      id: ''
    }
  },
  computed: {
    ...mapState(['city'])
  },
  created () {
    this.getDetailData()
  },
  methods: {
    getDetailData () {
      const detid = this.$route.query.id
      this.$http.get(`/houses/${detid}`, {}).then(res => {
        this.detailData = res.data.body
        this.coord = res.data.body.coord
        res.data.body.oriented.forEach((v, i) => {
          if (i === 0) {
            this.oriented = v
          }
        })
        console.log(this.detailData)
      })
    },
    map () {
      var map = new window.BMap.Map('container') // 创建Map实例
      // map.centerAndZoom(new window.BMap.Point(this.coord.latitude, this.coord.longitude), 11) // 初始化地图,设置中心点坐标和地图级别
      map.setCurrentCity(this.city) // 设置地图显示的城市 此项是必须设置的
    }
  }
}
</script>

<style scoped lang="scss">
.detail{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.det_head{
    width: 100%;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    background: #21b97a;
    color: #fff;
    >p{
      font-size: 16px;
    }
}
.detmain{
  width: 100%;
  flex: 1;
  overflow-y: scroll;
}
.banner{
  width: 100%;
  border-bottom: 1px solid #ccc;
  .my-swipe {
      width: 100%;
      height: 220px;
      img {
          width: 100%;
          height: 100%;
      }
  }
  >li{
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
  }
}
.desc{
  width: 100%;
  display: flex;
  justify-content: space-around;
  border-bottom: 1px solid #ccc;
  li{
    text-align: center;
    p:nth-child(1){
      font-size: 20px;
      font-weight: bold;
      color: red;
      margin-top: 10px;
      span{
        font-weight: 100;
        font-size: 14px;
      }
    }
    :nth-child(2){
      font-size: 16px;
      color: dimgray;
      margin: 5px 0;
    }
  }
}
.floor{
  width: 100%;
  padding: 10px 10px;
  li{
    width: 100%;
    display: flex;
    margin-top: 5px;
    font-size: 14px;
    p{
      width: calc(100%/2);
      span{
        color: dimgray;
        font-size: 12px;
      }
    }
  }
}
.community{
  width: 100%;
  margin-top: 10px;
  >li{
    width: 100%;
    height: 35px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 14px;
  }
  #container {
      overflow: hidden;
      width: 100%;
      height: 100px;
      margin: 0;
      font-family: "微软雅黑";
  }
}
.detfoot{
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  button{
    width: calc(100%/3);
    height: 100%;
    border: none;
    outline: none;
    font-size: 16px;
  }
  :nth-child(3){
    background: #21b97a;
    color: #fff;
  }
}
</style>
